﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;

namespace Sharp
{
    public class Email : MailMessage
    {
        public SmtpClient smtp { get; set; }
        public static System.Net.Mail.MailAddress noReply { get { return new System.Net.Mail.MailAddress("no-reply@ILM.com", "ILM"); } }
        public static String DnsSafeHost { get { return HttpContext.Current.Request.Url.DnsSafeHost; } }
        public Email()
        {
            smtp = new SmtpClient("smtp.postmarkapp.com", 25);
            smtp.Credentials = new NetworkCredential("1d58d7a1-8537-42f9-9aa0-5355fa5eb1a2", "1d58d7a1-8537-42f9-9aa0-5355fa5eb1a2");
        }

        public Email(string smtpserver, string smtpusername, string smtppassword)
        {
            smtp = new SmtpClient(smtpserver, 25);
            smtp.Credentials = new NetworkCredential(smtpusername, smtppassword);
        }

        public void Send(StateBag sb)
        {
            try
            {
                if (sb.Valid) 
                    smtp.Send(this);
            }
            catch (Exception e)
            {
                sb.ErrorMsg = "Error sending email: " + e.Message;
            }
        }
        
    }
}
